const connect = require('./base');
function timeline() {
    // 查询时光轴
    this.query = (req,callback) => {
        let sql = "select * from timeline where account=" + req.body.account;
        connect.getConnection((err, connection) => {
            if (err) {
                console.log('连接失败');
                return;
            } else {
                connection.query(sql, function (error, row, field) {
                    if (error) {
                        console.log('查询失败' + error.message);
                        return;
                    }
                    connection.release(); //每一次用完都要释放
                    callback(row);
                });
            }
        })
    };
    // 添加
    this.add = (req,callback) => {
        let sql = 'insert into timeline set ?';
        let data = {
            createDate: new Date().getTime(),
            color: req.body.color,
            content: req.body.content,
            account: req.body.account,
        };
        connect.getConnection((err, connection) => {
            if (err) {
                console.log('连接失败');
                return;
            } else {
                connection.query(sql,data, function (error, row, field) {
                    if (error) {
                        console.log('查询失败' + error.message);
                        return;
                    }
                    connection.release(); //每一次用完都要释放
                    callback(row);
                });
            }
        })
    }
}
module.exports = timeline;